How To Install Java with Apt on Ubuntu 20.04 |
您所在的位置:网站首页 › openjdk runtime environment › How To Install Java with Apt on Ubuntu 20.04 |
How To Install Java with Apt on Ubuntu 20.04
Ravi SaiveApril 15, 2021 Categories Java, Ubuntu 1 Comment
Java is one of the most popular programming languages and the JVM (Java’s virtual machine) is the run-time environment to run Java applications. These two platforms are required for much popular software that includes Tomcat, Jetty, Cassandra, Glassfish, and Jenkins. In this article, you will learn how to install Java Runtime Environment (JRE) and the Java Developer Kit (JDK) using the default apt package manager on Ubuntu 20.04 and Ubuntu 18.04. Installing the Default JRE in UbuntuThe painless way for installing Java is to use the version that comes with Ubuntu repositories. By default, Ubuntu packages with OpenJDK 11, which is an open-source alternative of the JRE and JDK. To install default Open JDK 11, first update the software package index: $ sudo apt update![]() Next, check for Java installation on the system. $ java -versionIf Java is not currently installed, you will get the following output. Command 'java' not found, but can be installed with: sudo apt install openjdk-11-jre-headless # version 11.0.10+9-0ubuntu1~20.04, or sudo apt install default-jre # version 2:1.11-72 sudo apt install openjdk-8-jre-headless # version 8u282-b08-0ubuntu1~20.04 sudo apt install openjdk-13-jre-headless # version 13.0.4+8-1~20.04 sudo apt install openjdk-14-jre-headless # version 14.0.2+12-1~20.04Now run the following command to install the default OpenJDK 11, which will provide Java Runtime Environment (JRE). $ sudo apt install default-jre![]() Once Java installed, you can verify the installation with: $ java -versionYou will get the following output: openjdk version "11.0.10" 2021-01-19 OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing) Installing the Default JDK in UbuntuOnce JRE installed, you might also need the JDK (Java Development Kit) in order to compile and run a Java-based application. To install the JDK, run the following command. $ sudo apt install default-jdk![]() After installation, verify the JDK installation by checking the version as shown. $ javac -versionYou will get the following output: javac 11.0.10 Setting the JAVA_HOME Environment Variable in UbuntuMost of the Java-based software programs use the JAVA_HOME environment variable to discover the Java installation location. To set the JAVA_HOME environment variable, first, discover where Java is installed by running the following command. $ readlink -f /usr/bin/javaYou will get the following output: /usr/lib/jvm/java-11-openjdk-amd64/bin/javaThen open /etc/environment file using nano text editor: $ sudo nano /etc/environmentAdd the following line at the end of the file, make sure to replace the location of your Java installation path. JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"Save the file and reload the file to apply the changes to your current session: $ source /etc/environmentVerify that the environment variable is set: $ echo $JAVA_HOMEYou will get the following output: /usr/lib/jvm/java-11-openjdk-amd64 ConclusionIn this tutorial, you learned how to install Java Runtime Environment (JRE) and the Java Developer Kit (JDK) on Ubuntu 20.04 and Ubuntu 18.04. Tags Ubuntu Tips Tutorial Feedback... Was this article helpful? If you don't find this article helpful or found some outdated info, issue or a typo, do post your valuable feedback or suggestions in the comments to help improve this article... If You Appreciate What We Do Here On TecMint, You Should Consider:TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all. If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation. We are thankful for your never ending support. Related Posts![]() Best Java IDE’s for Linux Developers ![]() How to Install Java 16 in Rocky Linux and AlmaLinux ![]() Object Oriented Approach of Java Programming and Encapsulation – Part 5 ![]() Understanding Java Compiler and Java Virtual Machine – Part 4 ![]() Understanding Java Class, Main Method and Loops Control in Java – Part 3 ![]() How Java Works and Understanding Code Structure of Java – Part 2 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |